<script>
	import {WS_URL} from "@/common/config.js"
	import { startGlobalTimer, stopGlobalTimer } from '@/util/timer.js'
	//#ifndef H5 
			let main = plus.android.runtimeMainActivity();
			// ！！！为了保证UHF正常关闭下电，延迟退出APP！！！
			if (uni.getSystemInfoSync().platform == 'android') {
				plus.runtime.quit = function() {
					setTimeout(() => {
						main.finish()
					}, 10)
				};
			}
		    //#endif
	var hhwUHFController;
	
	export default {
		globalData: {
			hhwUHFController: uni.requireNativePlugin('HL-HHWUHFController'),
			globalEvent: uni.requireNativePlugin('globalEvent'),
			
		},
		methods:{
			initWebsocket(data) {
				
				wsApi.connect(WS_URL, data);
				wsApi.onConnect(() => {
					console.log("ws链接成功")
				});
				wsApi.onMessage((cmd, msgInfo) => {
				})
				wsApi.onClose((e) => {
					console.log("连接关闭");
				});
			}
		},
		onLaunch: function() {
			// 定时器逻辑
			
			hhwUHFController = getApp().globalData.hhwUHFController;
		},
		onShow: function() {
			// 开启插件java接口的日志打印
			hhwUHFController.setDebuggable(true, result => {
				console.log("App Show", "setDebuggable: " + result);
			});
			// 初始化超高频（UHF），上电
			var enterTime = Date.now();
			var outTime = enterTime;
			hhwUHFController.initUhf(result => {
				outTime = Date.now();
				console.log("App Show", "initUHF: " + result, "cusTime: " + (outTime - enterTime));
				uni.showToast({
					title: result,
					icon: "none",
					duration: 1000
				});
			});
			// 启动全局定时器
			startGlobalTimer()
		},
		onHide: function() {
			// 关闭超高频（UHF），下电
			hhwUHFController.closeUhf(result => {
				console.log("App Hide", "closeUhf: " + result);
				uni.showToast({
					title: result,
					icon: "none",
					duration: 1000
				});
			});
			 // 停止全局定时器
			    stopGlobalTimer()
		},
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-ui/index.scss";
	
</style>
